package day06;

import java.util.Arrays;
import java.util.Random;

public class  MethodDemo {
    public static void main(String[] args) {
        //主方法是static静态方法 ，不能直接访问实例方法
        //同类中静态方法里可以直接访问静态方法
        //MethodDemo.say();//全称
        say("徐嘉豪");//String name="徐嘉豪"  //方法的重载
        say();//调用say()方法
        System.out.println("继续执行");
        say("ysq", 12);
        say("xjh", 81); //方法的重载 ，方法名相同，参数不同就行

        int a = sum(7, 6);
        System.out.println(a);//13
        int m = 5, n = 6;
        int b = sum(m, n);
        System.out.println(b);//11

        int[] c = generaArray(6, 9);
        System.out.println("c的长度为" + c.length);
        for (int i = 0; i < c.length; i++) {
            System.out.println(c[i]);
        }
        int[] d = generaArray(5, 50);
        System.out.println("第一个元素为" + d[0]);
        System.out.println("d的长度为" + d.length);
        Arrays.sort(d);//数组进行升序排序从小到大
        System.out.println("倒序看");
        for (int i = d.length - 1; i >= 0; i--) {
            System.out.println(d[i]);
        }
    }

    //有参有返回值
    public static int sum(int num1, int num2) {
        /*int num=num1+num2;
        return num;*/
        return num1 + num2;
    }

    //有参无返回值
    public static void say(String name) {
        System.out.println("大家好，我叫" + name);
    }

    //无参无返回值
    public static void say() {
        System.out.println("你好");
    }

    public static void say(String name, int age) {
        if (age > 80) { //大于80就return返回了
            return;
        }
        System.out.println("大家好，我叫" + name + ",今年" + age + "岁了");
    }

    public static void say(int age) {};//正确的重载
    //public static int say(){return  1}; //编译错误，重载与返回值无关，跟方法名和参数类型有效
    //public static void say(String adress);//编译错误，重载与参数名无关，跟方法名和参数类型有效

    public static int[] generaArray(int len, int max) {
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rand.nextInt(max + 1);//包括max
        }
        return arr;
    }
}
